<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>25.冻结对象API特性</title>
</head>

<body>
  <script>

    //Object.freeze` 冻结对象后不允许添加、删除、修改属性，writable、configurable 都标记为`false
    "use strict";
    const user = {
      name: "向军"
    };
    // 冻结属性， 增加、删除、修改属性都不再允许

    Object.freeze(user);
    console.log(JSON.stringify(Object.getOwnPropertyDescriptors(user), null, 2));
    //Object.isFrozen()方法判断一个对象是否被冻结
    if (!Object.isFrozen()) {
      user.name = "后盾人"; //Error 25.冻结对象API特性.html:25 Uncaught TypeError: Cannot assign to read only property 'name' of object '#<Object>
    }
  </script>
</body>

</html>